package com.glorysoft.wangnianxinpda.utils;

import android.util.Log;

import com.glorysoft.wangnianxinpda.base.Constant;
import com.glorysoft.wangnianxinpda.entity.net.RequestEntity;
import com.google.gson.Gson;
import com.google.gson.JsonObject;
import com.lzy.okgo.OkGo;
import com.lzy.okgo.callback.Callback;
import com.lzy.okgo.request.PostRequest;
import com.pda.platform.ui.ui_pdaplatform.callback.FreeUI_EntityCallBack;
import com.pda.platform.ui.ui_pdaplatform.utils_public.FreeApi_LogUtils;
import com.pda.platform.ui.ui_pdaplatform.utils_public.FreeApi_NetUtils;

import java.util.HashMap;
import java.util.Map;

/**
 * @Author Zhangjy
 * @Date 2021/6/28 13:37
 * Description :
 */
public class NetUtils {

//    public static <T> void requestPostNet(String messageName, String method, Object tag, JsonObject jsonString, FreeUI_EntityCallBack<T> callBack) {
//        RequestEntity requestEntity = new RequestEntity();
//        requestEntity.setBODY(jsonString);
////        BaseRequestEntity message = new BaseRequestEntity();
////        message.setRequest(requestEntity);
//        Map<String, String> map = new HashMap<>();
//        map.put("requestMessage", new Gson().toJson(requestEntity));
//        Log.e("requestData", "requestData: " + new Gson().toJson(requestEntity));
////        FreeApi_LogUtils.saveErrorMessages(Constant.NET_URL + "/api/Pda/" + method, "请求地址");
//        FreeApi_LogUtils.saveErrorMessages(Constant.NET_URL + "/api/" + method, "请求地址");
//        FreeApi_LogUtils.saveErrorMessages(map.toString(), "请求json");
//        String s = map.toString();
////        FreeApi_NetUtils.requestPostNet(Constant.NET_URL + "/api/Pda/"+ method + "?requestMessage=" + new Gson().toJson(requestEntity), tag, map, callBack);
////        FreeApi_NetUtils.requestGetNet(Constant.NET_URL + "/api/Pda/" + method, tag, map, callBack);
//        FreeApi_NetUtils.requestPostNet(Constant.NET_URL + "/api/" + method, tag, map, callBack);
//    }

    public static <T> void requestPostNet(String messageName, String method, Object tag, JsonObject jsonString, FreeUI_EntityCallBack<T> callBack) {
        RequestEntity requestEntity = new RequestEntity();
        requestEntity.setBODY(jsonString);
//        BaseRequestEntity message = new BaseRequestEntity();
//        message.setRequest(requestEntity);
//        Map<String, String> map = new HashMap<>();
//        map.put("requestMessage", new Gson().toJson(requestEntity));
        Log.e("requestData", "requestData: " + new Gson().toJson(requestEntity));
//        FreeApi_LogUtils.saveErrorMessages(Constant.NET_URL + "/api/Pda/" + method, "请求地址");
        FreeApi_LogUtils.saveErrorMessages(Constant.NET_URL + "/api/CIM/" + method, "请求地址");
        FreeApi_LogUtils.saveErrorMessages("requestMessage:" + new Gson().toJson(requestEntity), "请求json");
//        FreeApi_NetUtils.requestPostNet(Constant.NET_URL + "/api/Pda/"+ method + "?requestMessage=" + new Gson().toJson(requestEntity), tag, map, callBack);
//        FreeApi_NetUtils.requestGetNet(Constant.NET_URL + "/api/Pda/" + method, tag, map, callBack);
        OkGo.post(Constant.NET_URL + "/api/CIM/" + method)
                .tag(tag)
                .params("requestMessage", new Gson().toJson(requestEntity), new boolean[]{true})
                .execute((Callback<Object>) callBack);

//        FreeApi_NetUtils.requestPostNet(Constant.NET_URL + "/api/" + method, tag, map, callBack);
    }


}
